package com.jic.order.impl;

import java.lang.Long;
import java.util.List;

import com.jic.common.base.vo.Page;
import com.jic.common.base.vo.PageResult;
import com.jic.order.entity.OrderMerge;
import com.jic.order.entity.OrderSplitCondition;
import com.jic.order.manage.request.OrderSplitConditionEditRequest;
import com.jic.order.mapper.OrderMergeMapper;
import com.jic.order.service.OrderMergeService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 订单合单规则表
 * @author : 
 * @email : 
 * @since : 2020-09-14 11:43:48
 * @version : v1.0.0
 */
@Service
public class OrderMergeServiceImpl implements OrderMergeService{

    @Autowired
    private OrderMergeMapper orderMergeMapper;

    @Override
    public long editOrderMerge(OrderMerge orderMerge) {
        long flag ;
        if(orderMerge.getId()!=null&&orderMerge.getId()!=0){//修改
            flag = orderMergeMapper.update(orderMerge);
        }else {//新增
            flag = orderMergeMapper.insert(orderMerge);
        }

        return flag;
    }

    @Override
    public Boolean editOrderMergeStatus(String ids) {
        String[] arrId=ids.split(",");
        for(int i=0;i<arrId.length;i++){
            orderMergeMapper.editOrderMergeStatus(Long.valueOf(arrId[i]));
        }
        return true;
    }

    @Override
    public long insert(OrderMerge orderMerge) {
        long flag = orderMergeMapper.insert(orderMerge);
        return flag;
    }

    @Override
    public Boolean delete(String ids) {
        String[] arrId=ids.split(",");
        for(int i=0;i<arrId.length;i++){
            orderMergeMapper.delete(Long.valueOf(arrId[i]));
        }
        return true;
    }



    @Override
    public long update(OrderMerge orderMerge) {
        return orderMergeMapper.update(orderMerge);
    }

    @Override
    public OrderMerge queryByPrimaryKey(Long id){
        return orderMergeMapper.queryByPrimaryKey(id);
    }

    @Override
    public List<OrderMerge> query(OrderMerge orderMerge){
        return orderMergeMapper.query(orderMerge);
    }

    @Override
    public PageResult<OrderMerge> queryPage(OrderMerge orderMerge, Page pageQuery) {
        //计算下标
        int startIndex = (pageQuery.getStart() - 1) * pageQuery.getLimit();
        List<OrderMerge> list = orderMergeMapper.queryPage(startIndex, pageQuery.getLimit(), orderMerge);
        long count = orderMergeMapper.queryPageCount(orderMerge);
        PageResult pageResult = new PageResult();
        pageResult.setRows(list);
        pageResult.setTotal(count);
        return pageResult;
    }
}